﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using ShardingWTM.Models;


namespace ShardingWTM.ProjectManage.ViewModels.ProjectFileVMs
{
    public partial class ProjectFileListVM : BasePagedListVM<ProjectFile_View, ProjectFileSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "ProjectManage", dialogWidth: 800),
                this.MakeStandardAction("ProjectFile", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "ProjectManage"),
            };
        }


        protected override IEnumerable<IGridColumn<ProjectFile_View>> InitGridHeader()
        {
            return new List<GridColumn<ProjectFile_View>>{
                this.MakeGridHeader(x => x.ProjectName_view),
                this.MakeGridHeader(x => x.FileId).SetFormat(FileIdFormat),
                this.MakeGridHeaderAction(width: 200)
            };
        }
        private List<ColumnFormatInfo> FileIdFormat(ProjectFile_View entity, object val)
        {
            return new List<ColumnFormatInfo>
            {
                ColumnFormatInfo.MakeDownloadButton(ButtonTypesEnum.Button,entity.FileId),
                ColumnFormatInfo.MakeViewButton(ButtonTypesEnum.Button,entity.FileId,640,480),
            };
        }


        public override IOrderedQueryable<ProjectFile_View> GetSearchQuery()
        {
            var query = DC.Set<ProjectFile>()
                .CheckEqual(Searcher.ProjectId, x=>x.ProjectId)
                .Select(x => new ProjectFile_View
                {
				    ID = x.ID,
                    ProjectName_view = x.Project.ProjectName,
                    FileId = x.FileId,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class ProjectFile_View : ProjectFile{
        [Display(Name = "项目名称")]
        public String ProjectName_view { get; set; }

    }
}
